
import * as ActionTypes from '../constants/constants.js';
import { saveData, removeData, loadData } from '../util/utils.js';

export * from '../router/Home/reducers/reducers.js';
export * from '../router/Guest/reducers/reducers.js';


// 商家id
// export const shopnum = (state = util.shopnum) => state;

// 我的设备
export const myDevice = (state = null, action) => {
    switch (action.type) {
        case ActionTypes.setMyDevice:
            saveData('myDevice', action.data);
            return state = action.data
        case ActionTypes.clearMyDevice:
            removeData('myDevice')
            return state = null
        default:
            return state;
    }
}

// 电池信息
export const powerLevel = (state = 0, action) => {
    switch (action.type) {
        case ActionTypes.setPowerLevel:
            return state = action.data
        case ActionTypes.clearPowerLevel:
            return state = 0
        default:
            return state;
    }
}

// 信号强度
export const rssi = (state = 0, action) => {
    switch (action.type) {
        case ActionTypes.setRssi:
            return state = action.data
        case ActionTypes.clearRssi:
            return state = 0
        default:
            return state;
    }
}

// 当前是否为离线状态
export const offlineStatus = (state = false, action) => {
    switch (action.type) {
        case ActionTypes.setOfflineStatus:
            return state = action.data
        case ActionTypes.clearOfflineStatus:
            return state = false
        default:
            return state;
    }
}

// 当前是否为离线状态
export const connectStatus = (state = false, action) => {
    switch (action.type) {
        case ActionTypes.setConnectStatus:
            return state = action.data
        case ActionTypes.clearConnectStatus:
            return state = false
        default:
            return state;
    }
}

// 心率采集状态
export const ecgStatus = (state = false, action) => {
    switch (action.type) {
        case ActionTypes.setEcgStatus:
            return state = action.data
        case ActionTypes.clearEcgStatus:
            return state = false
        default:
            return state;
    }
}

// 心率采集数据
export const ecgData = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setEcgStatus:
            return state = action.data
        case ActionTypes.clearEcgStatus:
            return state = []
        default:
            return state;
    }
}

// // 商家详情
// export const shopInfo = (state = null, action) => {
//     switch (action.type) {
//         case ActionTypes.GET_SHOP_INFO:
//             return state = action.payload
//         default:
//             return state;
//     }
// }

// 登录用户信息
export const token = (state = '', action) => {
    switch (action.type) {
        case ActionTypes.setToken:
            saveData('token', action.data)
            return state = action.data
        case ActionTypes.clearToken:
            removeData('token')
            return state = ''
        default:
            return state;
    }
}

// 登录用户信息
export const user = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setUserInfo:
            saveData('userInfo', action.data)
            return state = action.data
        case ActionTypes.clearUserInfo:
            removeData('userInfo', action.data)
            return state = {}
        default:
            return state;
    }
}

// 分身币
export const coin = (state = {
    accountId: 0,
    coin: 0,
    id: 0,
    income: 0,
    pay: 0
}, action) => {
    switch (action.type) {
        case ActionTypes.setCoin:
            return state = action.data
        case ActionTypes.clearCoin:
            return state = {}
        default:
            return state;
    }
}

// cv
export const cv = (state = {
    accountId: 0,
    cv: 0,
    id: 0,
    income: 0,
    pay: 0
}, action) => {
    switch (action.type) {
        case ActionTypes.setCv:
            return state = action.data
        case ActionTypes.clearCv:
            return state = {}
        default:
            return state;
    }
}

// 积分
export const integral = (state = {
    accountId: 0,
    integral: 0,
    id: 0,
    income: 0,
    pay: 0
}, action) => {
    switch (action.type) {
        case ActionTypes.setIntegral:
            return state = action.data
        case ActionTypes.clearIntegral:
            return state = {}
        default:
            return state;
    }
}

// 登录信息
export const loginInfo = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setLoginInfo:
            saveData('loginInfo', action.data);
            return state = action.data
        case ActionTypes.clearLoginInfo:
            removeData('loginInfo')
            return state = {}
        default:
            return state;
    }
}

// 商品分类
export const categoryList = (state = {
    total: 0,
    size: 0,
    current: 0,
    pages: 0,
    records: []
}, action) => {
    switch (action.type) {
        case ActionTypes.setCategoryList:
            return state = action.data
        case ActionTypes.clearCategoryList:
            return state = {
                total: 0,
                size: 0,
                current: 0,
                pages: 0,
                records: []
            }
        default:
            return state;
    }
}

// 收货地址
export const addressList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setAddressList:
            return state = action.data
        case ActionTypes.clearAddressList:
            return state = []
        default:
            return state;
    }
}

// 默认收货地址
export const defaultAddres = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setDefaultAddres:
            return state = action.data
        case ActionTypes.clearDefaultAddres:
            return state = {}
        default:
            return state;
    }
}

// 发票
export const invoicesList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setInvoicesList:
            return state = action.data
        case ActionTypes.clearInvoicesList:
            return state = []
        default:
            return state;
    }
}

// 默认发票
export const defaultInvoice = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setDefaultInvoice:
            return state = action.data
        case ActionTypes.clearDefaultInvoice:
            return state = {}
        default:
            return state;
    }
}

// 购物车
export const shopCartList = (state = {
    total: 0,
    size: 0,
    current: 0,
    pages: 0,
    records: []
}, action) => {
    switch (action.type) {
        case ActionTypes.setShopCartList:
            return state = action.data
        case ActionTypes.clearShopCartList:
            return state = {
                total: 0,
                size: 0,
                current: 0,
                pages: 0,
                records: []
            }
        default:
            return state;
    }
}

// 购物车选中列表
export const shopCartCheckList = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setShopCartCheckList:
            return state = action.data
        case ActionTypes.clearShopCartCheckList:
            return state = {}
        default:
            return state;
    }
}

// 提交订单时选择的地址
export const submitOrderAddress = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setSubmitOrderAddress:
            return state = action.data
        case ActionTypes.clearSubmitOrderAddress:
            return state = {}
        default:
            return state;
    }
}

// 提交订单时选择的发票
export const submitOrderInvoice = (state = {}, action) => {
    switch (action.type) {
        case ActionTypes.setSubmitOrderInvoice:
            return state = action.data
        case ActionTypes.clearSubmitOrderInvoice:
            return state = {}
        default:
            return state;
    }
}

// 设置海报列表
export const billList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setBillList:
            return state = action.data
        case ActionTypes.clearBillList:
            return state = {}
        default:
            return state;
    }
}

// 设置绑定的亲人列表
export const accountList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setAccountList:
            return state = action.data
        case ActionTypes.clearAccountList:
            return state = {}
        default:
            return state;
    }
}


// 设置绑定申请列表
export const requestList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setRequestList:
            return state = action.data
        case ActionTypes.clearRequestList:
            return state = {}
        default:
            return state;
    }
}



// 板块列表
export const plateList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setPlateList:
            return state = action.data
        case ActionTypes.clearPlateList:
            return state = {}
        default:
            return state;
    }
}

// 热门板块列表
export const plateHotList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setPlateHotList:
            return state = action.data
        case ActionTypes.clearPlateHotList:
            return state = {}
        default:
            return state;
    }
}

// 板块帖子列表
export const cardList = (state = [], action) => {
    switch (action.type) {
        case ActionTypes.setCardList:
            return state = action.data
        case ActionTypes.clearCardList:
            return state = {}
        default:
            return state;
    }
}


// // 登录微信用户信息
// export const wxUser = (state = null, action) => {
//     switch (action.type) {
//         case ActionTypes.GET_WX_USER_INFO:
//             return state = action.data
//         default:
//             return state;
//     }
// }

export const statusHeight = (state = 0, action) => {
    switch (action.type) {
        case ActionTypes.setStatusHeight:
            return state = action.data
        default:
            return state;
    }
}
